<?php
class Register extends CI_Controller {
	
	function index(){
		
		$this->form_validation->set_rules('username', 'Email', 'required|xss_clean|trim|valid_email|max_lenght[240]');
		$this->form_validation->set_rules('password', 'Password', 'required|trim|matches[passconf]');
		$this->form_validation->set_rules('firstname', 'First Name', 'required|trim');
		$this->form_validation->set_rules('lastname', 'Last Name', 'required|trim');
		$this->form_validation->set_rules('lastname', 'Last Name', 'required|trim');
		$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|trim');
		
		if ($this->form_validation->run() == FALSE)
		{
			$this->load->view('register_view');
		}
		else
		{
			
			$username = $this->input->post('username');
			$password = $this->input->post('password');
			$firstname = $this->input->post('firstname');
			$lastname = $this->input->post('lastname');
			
			//$group_name = "members";
			
			//$username = 'ben.edmunds@gmail.com';
			//$password = '12345678';
			
			//if()
			
			if ($this->ion_auth->username_check($username))
			{
				$this->load->view('register_view');
				echo $this->ion_auth->messages();
				return;
			}
			
			$email = $username;
			$additional_data = array(
					'first_name' => $firstname,
					'last_name' => $lastname,
			);
			$group_name = 'members';
			
			$this->ion_auth->register($username, $password, $email, $additional_data, $group_name);
			
			$this->load->view('register_success');
			
		}
		
		/*
		if($this->input->post('username')){
			echo "posting";
			$this->load->view('register_view');
		} else {
			echo "getting view";
			$this->load->view('register_view');
		}
		*/
	}
	
}
?>